<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>学院管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="/webuploader/webuploader.css">

    <script src="/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="/webuploader/webuploader.js"></script>
    <script src="/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript">
        layui.config({
            base : "/layui/js/"
        }).use(['form', 'layedit', 'laydate','table','common'], function(){
            var form = layui.form ,laydate = layui.laydate ,table = layui.table ,layer = layui.layer,layedit = layui.layedit,common = layui.common,$ = layui.$;
            laydate.render({
                elem: '#projectCreateYear'
                ,type: 'year'
            });
            laydate.render({
                elem: '#yearMonthDay'

            });
            laydate.render({
                elem: '#year'

            });
            /* form.render();//更新渲染表单*/
            //分页查询

            layui.use('table', function(){
                var table = layui.table;

                table.render({
                    elem: '#TableId',
                    id:'TableId',
                    even: true,
                    url: '/college/findCollegeWithPage', //数据接口
                    limit:10,
                    limits:[10,20,30,50,100],
                    page: true ,//开启分页
                    cols: [[ //表头
                        {
                            field : 'clId',
                            title : 'Id',
                            type:   'checkbox'

                        },{
                            field : 'clName',
                            title : '学院名称',
                            edit: 'text'
                        },{
                            field : 'aaa',
                            title : '操作',
                            fixed : 'right',
                            width:  220,
                            align:'center',
                            toolbar: '#barDemo'
                        }]]
                });

                //监听单元格编辑
                table.on('edit(TableId)', function(obj){
                    var value = obj.value //得到修改后的值
                            ,data = obj.data //得到所在行所有键值
                            ,field = obj.field; //得到字段
                    var clId = data.clId;
                    var clName = data.clName;
                    $.ajax({
                        url : "/college/updateCollegeInfo",
                        type : 'post',
                        async: false,
                        data :  {'clId':clId,'clName':clName},
                        success : function(flag) {
                            if(flag == 1){
                                top.layer.msg("修改成功！", {icon: 6});
                                location.reload();
                            }else{
                                top.layer.msg("出错啦",{icon: 5,
                                    time:5000
                                });
                                location.reload();
                            }
                        },error:function(){

                        }
                    });
                    layer.msg('[ID: '+ data.clId +'] ' + field + ' 字段更改为：'+ value);
                });


                //工具按钮
                table.on('tool(TableId)', function(obj) {  //注：tool是工具条事件名，TableId是table原始容器的属性 lay-filter="对应的值"
                    var data = obj.data//获得当前行数据
                    var layEvent = obj.event; //获得 lay-event 对应的值
                   if (layEvent === 'del') { //删除

                        var data1 = data.clId;
                        layer.confirm('你确定要删除吗？', {
                            title: '删除',
                            resize: false,
                            btn: ['确定', '取消'],
                            btnAlign: 'c',
                            anim:1,
                            icon: 3
                        }, function () {
                            debugger;
                            $.ajax({
                                url : "/college/delCollegeInfo",
                                type : 'post',
                                async: false,
                                data :  {'clId':data1},
                                success : function(flag) {
                                    if(flag == true){
                                        ;
                                        top.layer.msg("删除成功", {icon: 6});
                                        obj.del(); //删除对应行（tr）的DOM结构
                                        location.reload();
                                    }else if(flag == false){
                                        top.layer.msg("系统异常，无法删除！",{icon: 5,
                                            time:5000
                                        });
                                        location.reload();
                                    }
                                },error:function(){

                                }
                            });
                        }, function () {
                            layer.msg('关闭', {
                                time: 1000, //1秒后自动关闭
                            });
                        });


                    }

                });
                /**查询*/
                $(".search_btn").click(function(){
                    var loading = layer.load(0,{ shade: [0.3,'#000']});
                    //监听提交

                    debugger;
                    table.reload('TableId',{
                        where: {
                            clName:$('#clName').val()
                        },
                        page: true,
                        done: function (res, curr, count) {
                            common.resizeGrid();
                            layer.close(loading);

                        }
                    });
                });





            });



        })






    </script>
    <script type="text/html" id="barDemo">

        <#--<a class="layui-btn layui-btn-xs" lay-event="detail">查看</a>-->
            <#--<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>-->
        <shiro:hasAnyRoles name="SUPERADMIN,CITY,CITY00,CITY01,CITY02,CITY03,CITY04,CITY05,CITY06,CITY07,CITY08,CITY09">
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </shiro:hasAnyRoles>
    </script>
</head>
<body>
<#--条件查询模块-->
<form class="layui-form layui-form-pane"  method="post" lay-filter="SearchFilter"  >
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">学院名称</label>
            <div class="layui-input-inline">
                <input type="text" name="clName" id="clName" value=""  class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <a class="layui-btn search_btn" lay-submit id="search_btn" lay-submit="" lay-filter="search">查询</a>
        </div>
        <div class="layui-inline" >
            <a class="layui-btn layui-btn-normal" href="/college/toCollegeAdd">添加</a>
        </div>
    </div>


</form>
<#--<div class="layui-layout-right" style="margin-top:160px;margin-right:5px;">单位</div>-->
<input type="hidden" value="${loginName}" id="loginName">
<#--<div class="layui-btn-group demoTable" style="margin-bottom: -10px;">-->
    <#--<shiro:hasAnyRoles name="SUPERADMIN">-->
        <#--<button class="layui-btn" data-type="delCheckData">批量删除</button>-->
    <#--</shiro:hasAnyRoles>-->
<#--&lt;#&ndash;<button class="layui-btn" data-type="copyData">拷贝</button>&ndash;&gt;-->
<#--&lt;#&ndash;<button class="layui-btn" data-type="copyData1">复制</button>&ndash;&gt;-->
<#--</div>-->

<table class="layui-table-cell" id="TableId" lay-filter="TableId" lay-data="{id: 'TableId'} skin: 'row'" ></table>

<div style="margin-bottom: 250px"></div>
</body>
</html>
